package com.ycsj.goldmedalnewconcept.teacher.fragment;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.ycsj.common.base.BaseLazyFragment;
import com.ycsj.common.utils.UiUtils;
import com.ycsj.goldmedalnewconcept.R;
import com.ycsj.goldmedalnewconcept.common.WxAppUtils;
import com.ycsj.goldmedalnewconcept.common.activity.LiveListActivity;
import com.ycsj.goldmedalnewconcept.common.adapter.HomeGvAdapter;
import com.ycsj.goldmedalnewconcept.common.bean.HomeInfo;
import com.ycsj.goldmedalnewconcept.teacher.activity.TeacherAssignHomeworkActivity;
import com.ycsj.goldmedalnewconcept.teacher.activity.TeacherChooseUnitActivity;
import com.ycsj.goldmedalnewconcept.teacher.activity.TeacherChooseUnitErrorListActivity;
import com.ycsj.goldmedalnewconcept.teacher.activity.TeacherCourseProgressActivity;
import com.ycsj.goldmedalnewconcept.teacher.activity.TeacherPetRankingActivity;
import com.ycsj.goldmedalnewconcept.teacher.activity.TeacherQuestionBankActivity;
import com.ycsj.goldmedalnewconcept.teacher.activity.TeacherScoreManagerActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 教师端教学Fragment
 * Created by Administrator on 2019/2/19 0019.
 */

public class TeacherHomeFragment extends BaseLazyFragment implements AdapterView.OnItemClickListener {

    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.gv)
    GridView mGv;

    //首页的展示的条目的数据集合
    private List<HomeInfo> homeInfos;

    //适配器对象
    private HomeGvAdapter adapter;

    //首页的栏目名称
//    private String[] itemNames = {"教学与反思", "课程进度", "布置练习", "金牌新概念1", "成绩管理", "题 库", "收听直播", "小小金", "宠物排名"};
//    private final String[] itemNames = {"教学与反思", "课程进度", "布置练习", "金牌新概念1", "成绩管理", "题 库", "收听直播", "宠物排名", "金牌新概念Ai"};
    private final String[] itemNames = {"教学与反思", "课程进度", "布置练习", "金牌新概念1", "成绩管理", "题 库", "收听直播", "宠物排名"};

    //首页的栏目的所有图片
//    private int[] itemResId = {R.drawable.teacher_jxyfs, R.drawable.teacher_kcjd, R.drawable.teacher_bzzy, R.drawable.teacher_jpxgl, R.drawable.teacher_cp, R.drawable.teacher_cjgl
//            , R.drawable.teacher_tk, R.drawable.teacher_stzb, R.drawable.teacher_apy, R.drawable.teacher_xxj, R.drawable.teacher_cwpm};
//    private final int[] itemResId = {R.drawable.teacher_jxyfs, R.drawable.teacher_kcjd, R.drawable.teacher_bzzy, R.drawable.teacher_jpxgl, R.drawable.teacher_cjgl
//            , R.drawable.teacher_tk, R.drawable.teacher_stzb, R.drawable.teacher_cwpm, R.drawable.jpj_work};

    private final int[] itemResId = {R.drawable.teacher_jxyfs, R.drawable.teacher_kcjd, R.drawable.teacher_bzzy, R.drawable.teacher_jpxgl, R.drawable.teacher_cjgl
            , R.drawable.teacher_tk, R.drawable.teacher_stzb, R.drawable.teacher_cwpm};

    public static final String TAG = TeacherHomeFragment.class.getName();

    //单体模式
    private static class LazyHolder {
        private static final TeacherHomeFragment INSTANCE = new TeacherHomeFragment();
    }

    public static final TeacherHomeFragment newInstance() {
        return LazyHolder.INSTANCE;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_teacher_home;
    }

    @Override
    public void lazyInit(View view, Bundle savedInstanceState) {

    }

    @Override
    protected void init(View view, Bundle savedInstanceState) {
        super.init(view, savedInstanceState);
        //初始化标题栏
        initTitle();

        //初始化数据
        initData();

        //初始化列表
        initGv();
    }


    /**
     * 初始化标题栏
     */
    private void initTitle() {
        ivBack.setVisibility(View.INVISIBLE);
        tvTitle.setText("金牌君");
    }

    /**
     * 初始化数据
     */
    private void initData() {
        homeInfos = new ArrayList<>();
        for (int i = 0; i < itemNames.length; i++) {
            HomeInfo info = new HomeInfo();
            info.resId = itemResId[i];
            info.name = itemNames[i];
            homeInfos.add(info);
        }
    }

    /**
     * 初始化列表的方法
     */
    private void initGv() {
        adapter = new HomeGvAdapter(getContext(), homeInfos, R.layout.gv_home);
        mGv.setAdapter(adapter);
        mGv.setOnItemClickListener(this);
    }


    /**
     * 条目点击事件
     *
     * @param adapterView
     * @param view
     * @param pos         点击的位置
     * @param l
     */
    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int pos, long l) {
        if (isDoubleClick(view)) {
        } else {
            switch (pos) {
                case 0:
                    //教学与反思
                    UiUtils.startActivity(getContext(), TeacherChooseUnitActivity.class);
                    break;
                case 1:
                    //课程进度
                    UiUtils.startActivity(getContext(), TeacherCourseProgressActivity.class);
                    break;
                case 2:
                    //布置练习
                    UiUtils.startActivity(getContext(), TeacherAssignHomeworkActivity.class);
                    break;
                case 3:
                    //金牌新概念1
                    UiUtils.startActivity(getContext(), TeacherChooseUnitErrorListActivity.class);
                    break;
                case 4:
                    //成绩管理
                    UiUtils.startActivity(getActivity(), TeacherScoreManagerActivity.class);
                    break;
                case 5:
                    //题库
                    UiUtils.startActivity(getContext(), TeacherQuestionBankActivity.class);
                    break;
                case 6:
                    //收听直播
                    UiUtils.startActivity(getContext(), LiveListActivity.class);
                    break;
                case 7:
                    //宠物排名
                    UiUtils.startActivity(getContext(), TeacherPetRankingActivity.class);
                    break;
                case 8:
                    //金牌单词王
                    WxAppUtils.launchWeApp(getContext());
                    break;

            }
        }
    }


}
